import { reactive, Ref, ref } from "vue";
import { ComponentImp, LowCodeImp, TableImp } from "./type";
const lowCodeInstance = Symbol("lowCodeInstance");

export class Table implements TableImp {
  private [lowCodeInstance]: LowCodeImp;
  tableRefs: any = new Map();
  customColumnsRenders = reactive(new Map()) 
  dataSource = new Map<string,Ref<any>>()
  constructor(lowcode: LowCodeImp) {
    this[lowCodeInstance] = lowcode as LowCodeImp;
  }

  setColumns(key: any,columns: any){
    this.customColumnsRenders.set(key,columns)
  }

  getColumns(key: any) {
    return this.customColumnsRenders
  }

  setDataSource(key: any,data: any){
    this.dataSource.get(key)&& (this.dataSource.get(key)!.value = data)
  }

  get tableColection() {
    const map = new Map();
    Object.values(this[lowCodeInstance].dataCenter)
      .filter((item: any) => item.component === "Table")
      .forEach((item: any) => {
        map.set(item.selector, item);
      });
    return map;
  }
}
